import type { LazyVue, RouteItem } from './types'
const templateComponent: LazyVue = () => import('../layout/template.vue')
const modules = import.meta.glob('../views/**/*.vue')
const routes: RouteItem[] = [
  {
    path: 'home',
    name: 'Home',
    meta: {
      title: '首页信息',
      icon: 'School',
    },
  },
  {
    path: '',
    redirect: { name: 'repairList' },
    meta: {
      title: '管理列表',
      icon: 'School',
    },
    children: [
      {
        path: 'userManage',
        name: 'repairList',
        meta: {
          title: '用户管理列表',
          icon: 'School',
        },
      },
      {
        path: 'home',
        name: 'detailHome',
        meta: {
          title: '用户管理列表',
          icon: 'School',
        },
      },
    ],
  },
]
/**
 *
 * @param list
 * @param parentPath
 *
 */
const addComponents = (list: RouteItem[], parentPath?: string) => {
  list.forEach((item) => {
    if (item.children) {
      item.component = templateComponent
      addComponents(item.children, item.path)
    } else if (!item.component) {
      console.log(modules)
      const path = (parentPath ? `${parentPath}/` : '') + item.path
      item.component = modules[`../views/${path}/index.vue`] as LazyVue
      console.log(item.component, `../views/${path}/index.vue`)
    }
  })
}
addComponents(routes)
export default routes
